package com.yksj.healthtalk.ui.doctorstation;

import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.DialogFragment;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.squareup.timessquare.CalendarFragment;
import com.squareup.timessquare.MonthCellDescriptor;
import com.squareup.timessquare.MonthView.Listener;
import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.comm.CommonExplainActivity;
import com.yksj.healthtalk.comm.DoubleBtnFragmentDialog;
import com.yksj.healthtalk.comm.DoubleBtnFragmentDialog.OnDilaogClickListener;
import com.yksj.healthtalk.comm.SingleBtnFragmentDialog;
import com.yksj.healthtalk.entity.DoctorServiceAddTimeEntity;
import com.yksj.healthtalk.net.http.AsyncHttpResponseHandler;
import com.yksj.healthtalk.net.http.HttpRestClient;
import com.yksj.healthtalk.net.http.JsonsfHttpResponseHandler;
import com.yksj.healthtalk.net.socket.SmartControlClient;
import com.yksj.healthtalk.services.CoreService;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.utils.DoctorServiceTimeUtile;
import com.yksj.healthtalk.utils.SystemUtils;
import com.yksj.healthtalk.utils.TimeUtil;
import com.yksj.healthtalk.utils.ToastUtil;
import com.yksj.healthtalk.utils.WheelUtils;

public class DoctorServiceAddTime extends BaseFragmentActivity implements OnClickListener{
	private CalendarFragment fragment;
	private TextView startTime;
	private TextView endTime;
	private EditText personNumber;
	private EditText moneyNumber;
	private String   mServiceTypeId;//2预约时段   3预约面访
	private String mType="addYuyueTime";
	private String ORDER_ON_OFF="0";
	private String serviceConment="[]";//服务内容id(多选,为数组)
	private String mDate="";//选择的日期
	private int mDay=0;//星期
	private List<DoctorServiceAddTimeEntity> entitys;
	private String REPEAT_FLAG="";//是否重复
	private ToggleButton repeatButton;
	private DoctorServiceAddTimeEntity mUpdateEntity;//要修改的时间段实体
	private String REPEAT_BATCH="";
	private TextView textAddress;//服务地点
	private TextView mServiceContent;
	private List<String> mListContent=new ArrayList<String>();//服务内容是否有
	private TextView serviceMingEcount;//服务名额
	private TextView serviceJinEEcount;//服务价格
	private String registMax;
	private String registMin;
	private String serviceMax;
	private String serviceMin;
	private JSONArray mRequestarray;//请求数据的array
	private String mServiceaddress;
	
	Handler handler=new Handler(){
		public void dispatchMessage(android.os.Message msg) {
			mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
		};
	};
	
	private ScrollView mScrollView;
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.doctor_add_service);
		initView();
		initData();
	}
  @Override
protected void onStart() {
	super.onStart();
	Intent intent =new Intent(this,CoreService.class);
	intent.setAction(CoreService.ACTION_FRAME_VIEW_VISIABLE);
	if(mServiceTypeId.equals("3")){//门诊
	intent.putExtra("className",this.getClass().getName()+"_1");
	}else{
		intent.putExtra("className",this.getClass().getName()+"_2");
	}
	startService(intent);
}
	private void initData() {
		HttpRestClient.doHttpDocotorAddTimeXianZhi(new AsyncHttpResponseHandler(this){
			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				try {
					/**
					 * 服务名额(1-100人)
					 */
					JSONObject json=new JSONObject(content);
					registMax = json.getString("REGISTEREDMAX");
					registMin = json.getString("REGISTEREDLEA");
					serviceMax = json.getString("SERVERMAX");
					serviceMin = json.getString("SERVERLEA");
					serviceJinEEcount.setText("服务价格("+serviceMin+"~"+serviceMax+"元/人)");
					serviceMingEcount.setText("服务名额("+registMin+"~"+registMax+"人)");
				} catch (JSONException e) {
				}
				
			}
		});
		
	}

	private void initView() {
		initTitle();
		titleLeftBtn.setOnClickListener(this);
		titleRightBtn2.setOnClickListener(this);
		titleRightBtn2.setVisibility(View.VISIBLE);
		titleRightBtn2.setText("确定");
		titleTextV.setText("添加服务时段");
		
		mScrollView = (ScrollView) findViewById(R.id.scroll);
		
		fragment = (CalendarFragment)getSupportFragmentManager().findFragmentByTag("calendar");
		repeatButton=(ToggleButton)findViewById(R.id.repeat_button);
	
		findViewById(R.id.service_content).setOnClickListener(this);
		findViewById(R.id.choice_service_time_begin).setOnClickListener(this);
		findViewById(R.id.choice_service_time_end).setOnClickListener(this);
		startTime = (TextView) findViewById(R.id.start_time);
		endTime = (TextView) findViewById(R.id.end_time);
		personNumber = (EditText)findViewById(R.id.person_number);
		moneyNumber = (EditText)findViewById(R.id.money_number);
		
		mServiceContent = (TextView) findViewById(R.id.status);
		mServiceTypeId = getIntent().getStringExtra("SERVICE_TYPE_ID");
		
		if(mServiceTypeId.equals("3")){
			findViewById(R.id.choice_service_address).setVisibility(View.VISIBLE);
			findViewById(R.id.line).setVisibility(View.VISIBLE);
			findViewById(R.id.choice_service_address).setOnClickListener(this);
			//choice_service_address
		}else{
			findViewById(R.id.choice_service_address).setVisibility(View.GONE);
			findViewById(R.id.line).setVisibility(View.GONE);
		}
		
		textAddress = (TextView) findViewById(R.id.address);
		textAddress.setOnClickListener(this);
		
		
		if(getIntent().hasExtra("entity")){
//			isClick=false;
			findViewById(R.id.view).setVisibility(View.VISIBLE);
			findViewById(R.id.edit_view).setVisibility(View.VISIBLE);
			mUpdateEntity=(DoctorServiceAddTimeEntity) getIntent().getSerializableExtra("entity");
			mType="updateYuyueTime";
			titleTextV.setText("编辑服务时段");
			if(mUpdateEntity.getISSLECT().equals("1")){
				mServiceContent.setText("已选择");	
			}else{
				mServiceContent.setText("未选择");
			}
			
			repeatButton.setChecked("1".equals(mUpdateEntity.getREPEAT_FLAG()));
			startTime.setText(DoctorServiceTimeUtile.getTime(mUpdateEntity.getSERVICE_TIME_BEGIN()) );
			startTime.setTag(DoctorServiceTimeUtile.getTimeObje(mUpdateEntity.getSERVICE_TIME_BEGIN()) );
			endTime.setText(DoctorServiceTimeUtile.getTime(mUpdateEntity.getSERVICE_TIME_END()) );
			endTime.setTag(DoctorServiceTimeUtile.getTimeObje(mUpdateEntity.getSERVICE_TIME_END()) );
			
			mDate=DoctorServiceTimeUtile.getYear(mUpdateEntity.getSERVICE_TIME_END())+DoctorServiceTimeUtile.getDate(mUpdateEntity.getSERVICE_TIME_END());
			personNumber.setText(mUpdateEntity.getSERVICE_MAX());
			moneyNumber.setText(mUpdateEntity.getSERVICE_PRICE());
			findViewById(R.id.delete_service).setVisibility(View.VISIBLE);
			findViewById(R.id.delete_service).setOnClickListener(this);
			REPEAT_BATCH=mUpdateEntity.getREPEAT_BATCH();
			SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
			
			try {
				Date date = format.parse(mUpdateEntity.getSERVICE_TIME_BEGIN());
				mDay=date.getDay();
			} catch (ParseException e) {
				
			}
			
			if(mServiceTypeId.equals("3")){
				textAddress.setText(mUpdateEntity.getSERVICE_PLACE());
				findViewById(R.id.choice_service_address).setBackgroundResource(R.drawable.textview_background_middle);
			}else{
				findViewById(R.id.choice_service_time).setBackgroundResource(R.drawable.textview_background_middle);	
			}
			//显示特殊收费人群 UI
			findViewById(R.id.choice_service_group).setVisibility(View.VISIBLE);
			findViewById(R.id.choice_service_group).setOnClickListener(this);
			findViewById(R.id.line2).setVisibility(View.VISIBLE);
//			//重复隐藏 修改布局
//			findViewById(R.id.check_repeat_line).setVisibility(View.GONE);
//			findViewById(R.id.choice_service_time_end).setBackgroundResource(R.drawable.textview_background_down);
		}else{
			findViewById(R.id.choice_service_group).setVisibility(View.GONE);
			findViewById(R.id.line2).setVisibility(View.GONE);
			findViewById(R.id.view).setVisibility(View.GONE);	
			//重复显示 修改布局
//			findViewById(R.id.check_repeat_line).setVisibility(View.VISIBLE);
//			findViewById(R.id.choice_service_time_end).setBackgroundResource(R.drawable.textview_background_middle);
			
			
			if(mServiceTypeId.equals("3")){
				findViewById(R.id.choice_service_address).setBackgroundResource(R.drawable.textview_background_down);
				findViewById(R.id.choice_service_time).setBackgroundResource(R.drawable.textview_background_middle);
			}else{
				findViewById(R.id.choice_service_time).setBackgroundResource(R.drawable.textview_background_down);
			}
			
			
		}
		
	repeatButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if(isChecked){
					SingleBtnFragmentDialog.showDefault(getSupportFragmentManager(),"选择重复后,系统将在重复日期为您自动设置该时间段为服务时段,请合理安排服务时段.");
				}
			}
		});
		entitys = getIntent().getParcelableArrayListExtra("entitys");
		Map<String,Date> busyMap = new LinkedHashMap<String, Date>();
		Map<String,Date> idleyMap = new LinkedHashMap<String, Date>();
		
		SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL, Locale.CHINA);
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMdd");
		for (DoctorServiceAddTimeEntity entity : entitys) {
			try {
				//闲
				if("0".equals(entity.getISBUZY())){
					Date date = format.parse(entity.getSERVICE_TIME_BEGIN());
					String str = format1.format(date);
					idleyMap.put(str,date);
					busyMap.remove(str);
				}else{
					Date date = format.parse(entity.getSERVICE_TIME_BEGIN());
					String str = format1.format(date);
					if(!idleyMap.containsKey(str)){
						busyMap.put(str,date);
					}
				}
			} catch (ParseException e) {
			}
		}
		if(busyMap!=null&&idleyMap!=null){
			Date dateNow = null;
			if(mUpdateEntity!=null){
				 try {
					dateNow=format.parse(mUpdateEntity.getSERVICE_TIME_BEGIN());
				} catch (ParseException e) {
					
				}
			}
			
			fragment.initCalender(dateNow, busyMap.values(),idleyMap.values(),new Listener() {
				
				@Override
				public void onChangeMonth(int i) {
				}
				//选择日期
				@Override
				public void handleClick(MonthCellDescriptor cell) {
				/*	if(cell.getRangeState() == RangeState.BUSY){
						ToastUtil.showBasicShortToast(getApplicationContext(), "所选时间已过期");
						return;
					}*/
					SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd");
					mDate = s.format(cell.getDate());
					mDay = cell.getDate().getDay();
					if(Integer.valueOf(mDate)<Integer.valueOf(TimeUtil.getNowDateFormat())){
						mDate="";
						ToastUtil.showShort(getApplicationContext(),"所选时间已过期!");
						return ;
					}
					//判断是否超过三十天限制
					Format format=new SimpleDateFormat("yyyyMMdd");
					long time=0;
					Date today=new Date();
					time=(today.getTime()/1000)+60*60*24*90;
					Date newDate=new Date();
					newDate.setTime(time*1000); 
					String string = format.format(newDate);
					if(Integer.valueOf(mDate)>Integer.valueOf(string)){
						mDate="";
						ToastUtil.showToastPanl("超过90天限制,无法设置时间段");
						return;
					}
					findViewById(R.id.edit_view).setVisibility(View.VISIBLE);
					handler.sendEmptyMessage(1000);
				}
			});
			
		}else{
			ToastUtil.showBasicShortToast(getApplicationContext(), "日期解析有误!");
		}
		serviceMingEcount=(TextView)findViewById(R.id.service_count);
		serviceJinEEcount=(TextView)findViewById(R.id.money_count);
	}
	
	
	
	
	
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			onBackPressed();
			break;
		case R.id.title_right2:
			SystemUtils.hideSoftBord(getApplicationContext(), moneyNumber);
			if(VerificationJudge())return ;
			
			//是否复用
			if(repeatButton.isChecked()){
					REPEAT_FLAG="1";
			}else{
					REPEAT_FLAG="0";
			}
				
			mRequestarray = new JSONArray();
				mRequestarray.put(mDay+"");//星期  必须以arry形式发送
				if(mServiceTypeId.equals("3")){
					mServiceaddress=textAddress.getText().toString();
				}else{
					mServiceaddress="";
				}
				
				submint(personNumber.getText().toString(),moneyNumber.getText().toString(),serviceConment,
						mDate+startTime.getTag().toString(),mDate+endTime.getTag().toString(),
						mRequestarray.toString(),mServiceaddress);//REPEAT_BATCH 修改状态才有	
			
			break;
		case R.id.service_content://选择服务内容页面
			{
				Intent intent=new Intent(this,DoctorServiceContentList.class);
				if(mUpdateEntity!=null){
					intent.putExtra("SERVICE_ITEM_ID", mUpdateEntity.getSERVICE_ITEM_ID());
				}else{
					if(mListContent!=null&&mListContent.size()!=0)
						intent.putStringArrayListExtra("isChoise", (ArrayList<String>)mListContent);
				}
				
				if(mServiceTypeId.equals("3")){//
					intent.putExtra("SERVICE_TYPE_SUB_ID", "22");//预约面访服务
				}else{
					intent.putExtra("SERVICE_TYPE_SUB_ID", "21");//网上咨询服务
				}
				intent.putExtra("SERVICE_TYPE_ID", mServiceTypeId);
				startActivityForResult(intent,1000);
			}
			break;
		case R.id.choice_service_time_begin:
			SystemUtils.hideSoftBord(getApplicationContext(), moneyNumber);
			showTime(v,startTime);
			break;
		case R.id.choice_service_time_end:
			SystemUtils.hideSoftBord(getApplicationContext(), moneyNumber);
			showTime(v,endTime);
			break;
		case R.id.delete_service://删除该服务时段 
			if(mUpdateEntity!=null)
			DoubleBtnFragmentDialog.showDefault(getSupportFragmentManager(), "删除此时段后，您有义务完成已成功预约的服务，此时段将不会有新的预约，您确定删除此时段？", "取消", "确定", new OnDilaogClickListener() {
				@Override
				public void onDismiss(DialogFragment fragment) {
					fragment.dismissAllowingStateLoss();
				}
				
				@Override
				public void onClick(DialogFragment fragment, View v) {
					JSONArray array=new JSONArray();
					JSONObject object=new JSONObject();
					try {
						object.put("SERVICE_ITEM_ID", mUpdateEntity.getSERVICE_ITEM_ID());
						object.put("SERVICE_DAY", mUpdateEntity.getSERVICE_TIME_BEGIN().substring(0, 8));
						object.put("REPEAT_FLAG", mUpdateEntity.getREPEAT_FLAG());
					} catch (JSONException e) {
						return;
					}
					array.put(object);
					deleteServiceListBefor(array.toString());
				}
			});
			break;
		case R.id.choice_service_address://服务地点
		case R.id.address:
			{
				Intent intent=new Intent(this,CommonExplainActivity.class);
				intent.putExtra("title", "服务地点");
				intent.putExtra("num", 200);
				intent.putExtra("content",textAddress.getText().toString());
				startActivityForResult(intent,2000);
			}
			break;
		case R.id.choice_service_group://特殊收费人群
			Intent intent=new Intent(this,DoctorSpecialServiceListActivity.class);
			intent.putExtra("SERVICE_ITEM_ID", mUpdateEntity.getSERVICE_ITEM_ID());
			startActivityForResult(intent, 1000);
			overridePendingTransition(R.anim.anim_enter, R.anim.anim_exit);
			break;
		}
	}
	
	private boolean VerificationJudge() {
		String personNum=personNumber.getText().toString();
		String moneyNum=moneyNumber.getText().toString();
		if("".equals(mDate)){
			ToastUtil.showBasicShortToast(getApplicationContext(), "请选择日期");
			return true;
		}
		
		if("".equals(personNum)||(Integer.valueOf(personNum)>Integer.valueOf(registMax))||(Integer.valueOf(personNum)<Integer.valueOf(registMin))){
			ToastUtil.showBasicShortToast(getApplicationContext(), "请填写服务名额("+registMin+"-"+registMax+"人)");
			return true;
		}
		
		if("".equals(moneyNum)||(Integer.valueOf(moneyNum)>Integer.valueOf(serviceMax))||(Integer.valueOf(moneyNum)<Integer.valueOf(serviceMin))){
			ToastUtil.showBasicShortToast(getApplicationContext(), "请填写服务价格("+serviceMin+"-"+serviceMax+"元/人)");
			return true;
		}
		if((startTime.getTag()==null||"".equals(startTime.getTag().toString()))){
			ToastUtil.showBasicShortToast(getApplicationContext(), "请选择开始时间");
			return true;
		}
		if((endTime.getTag()==null&&"".equals(endTime.getTag().toString()))){
			ToastUtil.showBasicShortToast(getApplicationContext(), "请选择结束时间");
			return true;
		}
		
		//结束时间要大于开始时间
		if(!(Integer.valueOf(startTime.getTag().toString())<Integer.valueOf(endTime.getTag().toString()))){
			ToastUtil.showBasicShortToast(getApplicationContext(), "结束时间要大于开始时间");
			return true;
		}
		
		//如果说是门诊  添加服务地点
		if(mServiceTypeId.equals("3")){
			if("".equals(textAddress.getText().toString())){
				ToastUtil.showBasicShortToast(getApplicationContext(), "请填写服务地点");
				return true;
			}
		}
		
		/*if(mListContent==null||mListContent.size()==0){
			if("".equals(serviceConment)||serviceConment.equals("[]")){
				ToastUtil.showBasicShortToast(getApplicationContext(), "请选择服务内容");
				return true;
			}
		}*/
		if(!"已选择".equals(mServiceContent.getText().toString())){
			ToastUtil.showBasicShortToast(getApplicationContext(), "请选择服务内容");
			return true;
		}
		
//		boolean isReturn=false;
//		long choicestart=Long.valueOf(mDate+startTime.getTag().toString());
//		long choicesend=Long.valueOf(mDate+endTime.getTag().toString());
//		for (int i = 0; i < entitys.size(); i++) {
//			DoctorServiceAddTimeEntity entity = entitys.get(i);
//			if(mUpdateEntity!=null&&entity.getSERVICE_ITEM_ID().equals(mUpdateEntity.getSERVICE_ITEM_ID()))
//				continue;
//			long entitystart=Long.valueOf(entity.getSERVICE_TIME_BEGIN().substring(0, entity.getSERVICE_TIME_BEGIN().length()-2));
//			long entityend=Long.valueOf(entity.getSERVICE_TIME_END().substring(0, entity.getSERVICE_TIME_END().length()-2));
//			
//			if((entitystart==choicestart&&entityend==choicesend)||(entitystart<choicestart&&entityend>choicestart)||(entitystart<choicesend&&entityend>choicesend)||(choicestart<entitystart&&choicesend>entitystart)){
//				isReturn=true;
//				break;
//			}
//		}
//		
//		if(isReturn){
//			ToastUtil.showBasicShortToast(getApplicationContext(), "您选择的时段已被其他预约占用，请选择其它时段或调整已占用预约服务的时段。");
//			return true;
//		}
		return false;
		
	}

	private void showTime(View v,final TextView data) {
		WheelUtils.showDateSelect(this,getLayoutInflater(),new OnClickListener() {
			@Override
			public void onClick(View v) {
				String[]time= (String[]) v.getTag();
				SimpleDateFormat format=new SimpleDateFormat("HHmm");
				int nowTime =Integer.valueOf(format.format(new Date()));
				if(nowTime>Integer.valueOf(time[0]+time[1])&&(TimeUtil.getNowDateFormat().equals(mDate))){
					ToastUtil.showBasicShortToast(getApplicationContext(), "所选时间不能小于当前系统时间");
				}else{
					data.setTag(time[0]+time[1]);
					data.setText(time[0]+":"+time[1]);
				}
			}
		});
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if(resultCode!=Activity.RESULT_OK)return;
		switch (requestCode) {
		case 1000:
			if(data.hasExtra("parame")){
				serviceConment=data.getStringExtra("parame");
				if(serviceConment==null||"[]".equals(serviceConment)){
					serviceConment="[]";
					mServiceContent.setText("未选择");
				}else{
					if(mListContent==null){
						mListContent=new ArrayList<String>();
					}
					mListContent.clear();
					mListContent.addAll(com.alibaba.fastjson.JSONArray.parseArray(serviceConment,String.class));
					mServiceContent.setText("已选择");
				}
			}
			break;
		case 2000:
			if(data.hasExtra("content")){
				textAddress.setText(data.getStringExtra("content"));
			}
			break;
		}
	}
	
	//提交
	private void submint(String perSonNum,String price,String service_desc,String time_begin,
			String time_end,String PARAME,String address) {
		String SERVICE_ITEM_ID="";
		if(mUpdateEntity!=null)SERVICE_ITEM_ID=mUpdateEntity.getSERVICE_ITEM_ID();
		if(service_desc.equals("[]"))service_desc=mUpdateEntity.getSERVICE_ITEM_DESC();
		
		HttpRestClient.doHttpCreateService(SERVICE_ITEM_ID,mType,mServiceTypeId,ORDER_ON_OFF,perSonNum,
				price,service_desc,time_begin,time_end,PARAME,REPEAT_BATCH,REPEAT_FLAG,address,new JsonsfHttpResponseHandler(this){
					@Override
					public void onSuccess(final com.alibaba.fastjson.JSONObject object) {
					super.onSuccess(object);
					if(object.containsKey("error_code")&&object.getString("error_code").equals("550")){
						
						DoubleBtnFragmentDialog.showDefault(getSupportFragmentManager(), object.getString("error_message"), "取消", "继续", new OnDilaogClickListener() {
							
							@Override
							public void onDismiss(DialogFragment fragment) {
								fragment.dismissAllowingStateLoss();
							}
							
							@Override
							public void onClick(DialogFragment fragment, View v) {
								if(mUpdateEntity==null){
									mType="PeriodCovered";
								}else{
									mType="updateYuyueTimeCovered";
								}
								submint(personNumber.getText().toString(),moneyNumber.getText().toString(),serviceConment,
										mDate+startTime.getTag().toString(),mDate+endTime.getTag().toString(),
										mRequestarray.toString(),mServiceaddress);//REPEAT_BATCH 修改状态才有	
								
							}
						});
						
					}else if(object.containsKey("error_code")){
						ToastUtil.showBasicShortToast(getApplicationContext(), object.getString("error_message"));
					}else{
						if(mUpdateEntity==null){
							DoubleBtnFragmentDialog.showDefault(getSupportFragmentManager(),  "添加服务时段成功,可以为所添加时段设置特殊收费人群.", "以后再说","现在设置",new OnDilaogClickListener() {
								@Override
								public void onDismiss(DialogFragment fragment) {
									fragment.dismissAllowingStateLoss();
									setResult(RESULT_OK, getIntent());
									finish();
									ToastUtil.showShort("处理成功");
								}
								@Override
								public void onClick(DialogFragment fragment, View v) {
									Intent intent = new Intent(DoctorServiceAddTime.this,DoctorSpecialServiceListActivity.class);
//									String SERVICE_ITEM_ID=object.getJSONArray("list").getJSONObject(0).getString("SERVICE_ITEM_ID");
									if(TextUtils.isEmpty(object.getString("SERVICE_ITEM_ID")))return;
									intent.putExtra("SERVICE_ITEM_ID",object.getString("SERVICE_ITEM_ID"));
									startActivity(intent);
									DoctorServiceAddTime.this.finish();
								}
							});	
						}else{
							setResult(RESULT_OK, getIntent());
							finish();
							ToastUtil.showShort("处理成功");
						}
					}
					
					}
		});
	}
	
	
	
	
//	删除预约或者时段前所调用的接口
//	ServiceSetServlet33
//	Type=beforeDeleteYuyue
//	CUSTOMER_ID 客户id
//	SERVICE_TYPE_ID 类型id
//	PARAME 将服务项id（即SERVICE_ITEM_ID）装进数组打成jsonArray发过来  
//
//	返回参数：如果有error_code，则提示error_message并且不能继续往下操作
//		  没有则提示message
	
	//删除之前调用接口
	private void deleteServiceListBefor(final String PARAME) {
		HttpRestClient.doHttpDeleteServiceTimeBefor("beforeDeleteYuyue",SmartControlClient.getControlClient().getUserId(),PARAME,new JsonsfHttpResponseHandler(this){
			@Override
			public void onSuccess(int statusCode,com.alibaba.fastjson.JSONObject response) {

				super.onSuccess(statusCode, response);
				if(response.containsKey("error_code")){
					String message=response.getString("error_message");
					SingleBtnFragmentDialog.showDefault(getSupportFragmentManager(),  message);
				}else{
					DoubleBtnFragmentDialog.showDefault(getSupportFragmentManager(),  response.getString("message"), "放弃", "删除", new OnDilaogClickListener() {
						
						@Override
						public void onDismiss(DialogFragment fragment) {
							fragment.dismissAllowingStateLoss();
						}
						
						@Override
						public void onClick(DialogFragment fragment, View v) {
							HttpRestClient.doHttpDeleteServiceTimeBefor("deleteSeleteYuyueTime", SmartControlClient.getControlClient().getUserId(), PARAME, new JsonsfHttpResponseHandler(DoctorServiceAddTime.this){
								@Override
								public void onSuccess(int statusCode,com.alibaba.fastjson.JSONObject response) {
									super.onSuccess(statusCode, response);
									if(response.containsKey("error_code")){
										SingleBtnFragmentDialog.showDefault(getSupportFragmentManager(), response.getString("error_message"));
									}else{
										finish();
									}
								}
							});
						
							
						}
					});
				}
			
			}
		});
		
	}
}
